package com.ming.elm.controller;

import com.ming.elm.po.Orders;
import com.ming.elm.service.OrdersService;
import com.ming.elm.service.impl.OrdersServiceImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

public class OrdersController {
    private OrdersService os = new OrdersServiceImpl();

    public Object createOrders(HttpServletRequest request) throws Exception {
        String userId = request.getParameter("userId");
        String str1 = request.getParameter("businessId");
        String str2 = request.getParameter("daId");
        String str3 = request.getParameter("orderTotal");
        Integer businessId = Integer.valueOf(str1);
        Integer daId = Integer.valueOf(str2);
        Double orderTotal = Double.valueOf(str3);

        // 返回的是订单主键
        Integer key = os.createOrders(userId, businessId, daId, orderTotal);

        return key;
    }

    public Object getOrdersById(HttpServletRequest request) throws Exception {
        String str = request.getParameter("orderId");
        Integer orderId = Integer.valueOf(str);
        Orders orders = os.getOrdersById(orderId);


        return orders;
    }

    public Object listOrdersByUserId(HttpServletRequest request) throws Exception {
        String userId = request.getParameter("userId");
        List<Orders> list = os.listOrdersByUserId(userId);
        return list;
    }

    public Object listOrdersDetailByUserId(HttpServletRequest request) throws Exception{
        String userId = request.getParameter("userId");
        List<Orders> list = os.listOrdersDetailByUserId(userId);
        return list;

    }
}
